package com.cain.calendar.tool;

import java.util.Calendar;

/**
 * Created by Cain on 2016/6/25.
 * 自定义时间类，用于获取各种有关此项目时间的数据
 */
public class MyCalendar {

    /**
     * 获取指定月份的最大天数
     * @param year
     * @param month
     * @return
     */
    public static int getNumberOfDays(int year, int month) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month, 1);
        calendar.roll(Calendar.DATE, -1);
        int maxDate = calendar.get(Calendar.DATE);
        return maxDate;
    }

    /**
     * 判断是否是同一天
     * @param year1
     * @param month1
     * @param day1
     * @param year2
     * @param month2
     * @param day2
     * @return
     */
    public static boolean isTheSameDay(int year1, int month1, int day1, int year2, int month2, int day2) {
        if (year1 == year2 && month1 == month2 && day1 == day2)
            return true;
        else
            return false;
    }

    /**
     * 判断是否是今天
     * @param year
     * @param month
     * @param day
     * @return
     */
    public static boolean isToday(int year, int month, int day) {
        Calendar current = Calendar.getInstance();
        return isTheSameDay(year, month, day,
                current.get(Calendar.YEAR), current.get(Calendar.MONTH), current.get(Calendar.DAY_OF_MONTH));
    }

    /**
     * 判断是否是当月
     * @param year
     * @param month
     * @return
     */
    public static boolean isThisMonth(int year, int month) {
        Calendar current = Calendar.getInstance();
        if (year == current.get(Calendar.YEAR) && month == current.get(Calendar.MONTH))
            return true;
        else
            return false;
    }
}
